home *** CD-ROM | disk | FTP | other *** search
/ Aminet 45 / Aminet 45 (2001)(GTI - Schatztruhe)[!][Oct 2001].iso / Aminet / util / misc / ReportPlus.lha / reportplus / source / f12.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-08-20  |  16.0 KB  |  521 lines

  1. #include <exec/types.h>
  2. #include <exec/memory.h>
  3. #include <intuition/intuition.h>
  4. #include <intuition/gadgetclass.h>
  5. #include <workbench/icon.h>
  6. #include <workbench/workbench.h>
  7. #include <dos/dosextens.h>
  8.  
  9. #include "rp.h" // before icon protos
  10.  
  11. #include <clib/alib_protos.h>
  12. #include <clib/exec_protos.h>
  13. #include <clib/intuition_protos.h>
  14. #include <clib/icon_protos.h>
  15. #include <clib/dos_protos.h>
  16. #include <pragmas/icon_pragmas.h>
  17. #include <reaction/reaction.h>
  18.  
  19. #include <gadgets/chooser.h>
  20. #include <pragmas/chooser_pragmas.h>
  21. #include <gadgets/string.h>
  22. #include <pragmas/string_pragmas.h>
  23. #include <gadgets/checkbox.h>
  24. #include <pragmas/checkbox_pragmas.h>
  25. #include <gadgets/layout.h>
  26. #include <pragmas/layout_pragmas.h>
  27. #include <gadgets/button.h>
  28. #include <pragmas/button_pragmas.h>
  29. #include <images/label.h>
  30. #include <pragmas/label_pragmas.h>
  31. #include <proto/label.h>
  32. #include <classes/window.h>
  33. #include <pragmas/window_pragmas.h>
  34.  
  35. #include <stdlib.h>
  36. #include <string.h>
  37.  
  38. #define SCAN_P 25
  39.  
  40. AGLOBAL        Object*     Window12Object    = NULL;
  41. AGLOBAL ABOOL              quit              = FALSE;
  42. AGLOBAL struct Gadget*     icon_gadgets[GIDS_12 + 1];
  43. AGLOBAL struct IconStruct  icon =
  44. {   TRUE, FALSE,
  45.     WBTOOL
  46. };
  47.  
  48. // from rp.c
  49. IMPORT TEXT                IOBuffer[LONGESTFIELD + 1];
  50. IMPORT SBYTE               page;
  51. IMPORT TEXT                asldir[VLONGFIELD + 1];
  52. IMPORT ULONG               signal;
  53. IMPORT struct Window*      MainWindowPtr;
  54. IMPORT struct Screen*      ScreenPtr;
  55. IMPORT struct SharedStruct shared;
  56. IMPORT struct Library     *ButtonBase,
  57.                           *CheckBoxBase,
  58.                           *ChooserBase,
  59.                           *IconBase,
  60.                           *LabelBase,
  61.                           *LayoutBase,
  62.                           *StringBase,
  63.                           *WindowBase;
  64. IMPORT struct Menu*        MenuPtr;
  65. IMPORT ABOOL               done;
  66. IMPORT TEXT                aslresult[VLONGFIELD + 1];
  67.  
  68. MODULE ABOOL               stop;
  69. MODULE STRPTR IconOptions[7 + 1] =
  70. {   "Disk",
  71.     "Drawer",
  72.     "Tool",
  73.     "Project",
  74.     "Trashcan",
  75.     "Device",
  76.     "Kickstart",
  77.     "AppIcon"
  78. };
  79. /* icon.type is the same as the values used by the system. So, the
  80. value used by the gadget is one less than the actual value. */
  81.  
  82. AGLOBAL void icon1(void)
  83. {   ULONG               i;
  84.     struct List         ChooserList;
  85.     struct ChooserNode *ChooserNodePtr[7 + 1];
  86.     struct Hook         Hook12Struct;
  87.  
  88.     shared.pathname[0] = 0;
  89.  
  90.     NewList(&ChooserList);
  91.     for (i = 0; i <= 7; i++)
  92.     {   if (!(ChooserNodePtr[i] = (struct ChooserNode *) AllocChooserNode(CNA_Text, IconOptions[i], TAG_DONE)))
  93.         {   rq("Can't allocate chooser node!");
  94.         }
  95.         AddTail(&ChooserList, (struct Node *) ChooserNodePtr[i]);
  96.     } // automatically freed by ReAction at DisposeObject() time
  97.  
  98.     /* Create the window object. */
  99.     lockscreen();
  100.     gadtools();
  101.     InitHook(&Hook12Struct, Hook12Func, NULL);
  102.  
  103.     if (!(Window12Object =        NewObject(WINDOW_GetClass(), NULL,
  104.     // window
  105.     WA_PubScreen,                 ScreenPtr,
  106.     WA_ScreenTitle,               "Report+",
  107.     WA_Title,                     "Report+: Icon Processor",
  108.     WA_Activate,                  TRUE,
  109.     WA_DepthGadget,               TRUE,
  110.     WA_DragBar,                   TRUE,
  111.     WA_CloseGadget,               TRUE,
  112.     WA_SizeGadget,                TRUE,
  113.     WA_IDCMP,                     IDCMP_RAWKEY,
  114.     WINDOW_IDCMPHook,             &Hook12Struct,
  115.     WINDOW_IDCMPHookBits,         IDCMP_RAWKEY,
  116.     WINDOW_MenuStrip,             MenuPtr,
  117.     WINDOW_Position,              WPOS_CENTERSCREEN,
  118.     WINDOW_ParentGroup,           icon_gadgets[GID_12_LY1] =
  119.                                   NewObject(LAYOUT_GetClass(), NULL,
  120.             // root-layout
  121.             LAYOUT_Orientation,       LAYOUT_ORIENT_VERT,
  122.             LAYOUT_SpaceOuter,        TRUE,
  123.             LAYOUT_DeferLayout,       TRUE,
  124.             LAYOUT_AddChild,          icon_gadgets[GID_12_CH1] =
  125.                                       NewObject(CHOOSER_GetClass(), NULL,
  126.                 // chooser
  127.                 GA_ID,                GID_12_CH1,
  128.                 CHOOSER_PopUp,        TRUE,
  129.                 CHOOSER_Labels,       &ChooserList,
  130.                 CHOOSER_Selected,     (WORD) (icon.type - 1),
  131.                 TAG_END),
  132.             CHILD_WeightedHeight,     0,
  133.             LAYOUT_AddChild,          icon_gadgets[GID_12_CB1] =
  134.                                       NewObject(CHECKBOX_GetClass(), NULL,
  135.                 // checkbox
  136.                 GA_ID,                GID_12_CB1,
  137.                 GA_RelVerify,         TRUE,
  138.                 GA_Text,              "_Optimize colours?",
  139.                 GA_Selected,          (BOOL) icon.optimize,
  140.                 TAG_END),
  141.             CHILD_WeightedHeight,     0,
  142.             LAYOUT_AddChild,          icon_gadgets[GID_12_CB2] =
  143.                                       NewObject(CHECKBOX_GetClass(), NULL,
  144.                 // checkbox
  145.                 GA_ID,                GID_12_CB2,
  146.                 GA_RelVerify,         TRUE,
  147.                 GA_Text,              "Preserve p_lanar data?",
  148.                 GA_Selected,          (BOOL) icon.planar,
  149.                 TAG_END),
  150.             CHILD_WeightedHeight,     0,
  151.             LAYOUT_AddChild,          NewObject(LAYOUT_GetClass(), NULL,
  152.                 // layout
  153.                 LAYOUT_Orientation,   LAYOUT_ORIENT_HORIZ,
  154.                 GA_BackFill,          NULL,
  155.                 LAYOUT_SpaceOuter,    TRUE,
  156.                 LAYOUT_VertAlignment, LALIGN_CENTER,
  157.                 LAYOUT_HorizAlignment,LALIGN_CENTER,
  158.                 LAYOUT_BevelStyle,    BVS_FIELD,
  159.                 LAYOUT_AddImage,      NewObject(LABEL_GetClass(), NULL,
  160.                     // label
  161.                     LABEL_Text,       "_Pathname(s):",
  162.                     LABEL_Justification,LJ_LEFT,
  163.                     TAG_END),
  164.                 LAYOUT_AddChild,      icon_gadgets[GID_12_ST1] =
  165.                                       NewObject(STRING_GetClass(), NULL,
  166.                     // string        
  167.                     GA_ID,            GID_12_ST1,
  168.                     STRINGA_TextVal,  shared.pathname,
  169.                     STRINGA_MinVisible,35,
  170.                     TAG_END),
  171.                 LAYOUT_AddChild,      icon_gadgets[GID_12_BU1] =
  172.                                       NewObject(NULL, "button.gadget",
  173.                     // button
  174.                     GA_ID,            GID_12_BU1,
  175.                     GA_RelVerify,     TRUE,
  176.                     BUTTON_AutoButton,BAG_POPFILE,
  177.                     TAG_END),
  178.                 CHILD_WeightedWidth,  0,
  179.                 TAG_END),
  180.             CHILD_WeightedHeight,     0,
  181.             LAYOUT_AddChild,          icon_gadgets[GID_12_ST2] =
  182.                                       NewObject(STRING_GetClass(), NULL,
  183.                 // string        
  184.                 GA_ReadOnly,          TRUE,
  185.                 GA_ID,                GID_12_ST2,
  186.                 STRINGA_TextVal,      "Ready.",
  187.                 TAG_END),
  188.             CHILD_WeightedHeight,     0,
  189.             LAYOUT_AddChild,          NewObject(LAYOUT_GetClass(), NULL,
  190.                 // layout
  191.                 LAYOUT_Orientation,   LAYOUT_ORIENT_HORIZ,
  192.                 GA_BackFill,          NULL,
  193.                 LAYOUT_SpaceOuter,    TRUE,
  194.                 LAYOUT_VertAlignment, LALIGN_CENTER,
  195.                 LAYOUT_HorizAlignment,LALIGN_CENTER,
  196.                 LAYOUT_BevelStyle,    BVS_FIELD,
  197.                 LAYOUT_AddChild,      icon_gadgets[GID_12_BU3] =
  198.                                       NewObject(NULL, "button.gadget",
  199.                     // button
  200.                     GA_ID,            GID_12_BU3,
  201.                     GA_RelVerify,     TRUE,
  202.                     GA_Text,          "Pro_cess",
  203.                 TAG_END),
  204.                 CHILD_WeightedWidth,  50,
  205.                 LAYOUT_AddChild,      icon_gadgets[GID_12_BU4] =
  206.                                       NewObject(NULL, "button.gadget",
  207.                     // button
  208.                     GA_ID,            GID_12_BU2,
  209.                     GA_RelVerify,     TRUE,
  210.                     GA_Text,          "Stop",
  211.                     GA_Disabled,      TRUE,
  212.                     TAG_END),
  213.                 CHILD_WeightedWidth,  50,
  214.                 TAG_END),
  215.             CHILD_WeightedHeight,     0,
  216.             LAYOUT_AddChild,          icon_gadgets[GID_12_BU2] =
  217.                                       NewObject(NULL, "button.gadget",
  218.                 // button
  219.                 GA_ID,                GID_12_BU2,
  220.                 GA_RelVerify,         TRUE,
  221.                 GA_Text,              "Menu",
  222.                 TAG_END),
  223.             CHILD_WeightedHeight,     0,
  224.             TAG_END),
  225.     TAG_END)
  226.     ))
  227.     {   rq("Can't create ReAction objects!");
  228.     }
  229.     unlockscreen();
  230.  
  231.     // Open the window.
  232.  
  233.     if (!(MainWindowPtr = (struct Window *) DoMethod(Window12Object, WM_OPEN, NULL)))
  234.     {   rq("Can't open ReAction window!");        
  235.     }
  236.     // Obtain the window wait signal mask.
  237.     GetAttr(WINDOW_SigMask, Window12Object, &signal);
  238.     ActivateLayoutGadget(icon_gadgets[GID_12_LY1], MainWindowPtr, NULL, (Object) icon_gadgets[GID_12_ST1]);
  239.     loop();
  240.     closewindow();
  241.     if (quit)
  242.     {   cleanexit(EXIT_SUCCESS);
  243. }   }
  244.  
  245. AGLOBAL void icon_do(void)
  246. {   STRPTR stringptr;
  247.  
  248.     if (!(GetAttr
  249.     (   CHOOSER_Selected, icon_gadgets[GID_12_CH1], (ULONG *) &(icon.type)
  250.     )))
  251.     {   rq("Unsupported inquiry!"); // should never happen
  252.     }
  253.     icon.type++;
  254.     if (!(GetAttr
  255.     (   STRINGA_TextVal, icon_gadgets[GID_12_ST1], (ULONG *) &stringptr
  256.     )))
  257.     {   rq("Unsupported inquiry!"); // should never happen
  258.     }
  259.     strcpy(shared.pathname, stringptr);
  260.     // to other similar parts of f12.c
  261.     if (!(GetAttr
  262.     (   GA_Selected, icon_gadgets[GID_12_CB1], (ULONG *) &(icon.optimize)
  263.     )))
  264.     {   rq("Unsupported inquiry!"); // should never happen
  265.     }
  266.     if (!(GetAttr
  267.     (   GA_Selected, icon_gadgets[GID_12_CB2], (ULONG *) &(icon.planar)
  268.     )))
  269.     {   rq("Unsupported inquiry!"); // should never happen
  270.     }
  271.  
  272.     SetGadgetAttrs
  273.     (   icon_gadgets[GID_12_CH1], MainWindowPtr, NULL,
  274.         GA_Disabled, TRUE,
  275.         TAG_END
  276.     );
  277.     SetGadgetAttrs
  278.     (   icon_gadgets[GID_12_CB1], MainWindowPtr, NULL,
  279.         GA_Disabled, TRUE,
  280.         TAG_END
  281.     );
  282.     SetGadgetAttrs
  283.     (   icon_gadgets[GID_12_CB2], MainWindowPtr, NULL,
  284.         GA_Disabled, TRUE,
  285.         TAG_END
  286.     );
  287.     SetGadgetAttrs
  288.     (   icon_gadgets[GID_12_ST1], MainWindowPtr, NULL,
  289.         GA_Disabled, TRUE,
  290.         TAG_END
  291.     );
  292.     SetGadgetAttrs
  293.     (   icon_gadgets[GID_12_BU1], MainWindowPtr, NULL,
  294.         GA_Disabled, TRUE,
  295.         TAG_END
  296.     );
  297.     SetGadgetAttrs
  298.     (   icon_gadgets[GID_12_BU2], MainWindowPtr, NULL,
  299.         GA_Disabled, TRUE,
  300.         TAG_END
  301.     );
  302.     SetGadgetAttrs
  303.     (   icon_gadgets[GID_12_BU3], MainWindowPtr, NULL,
  304.         GA_Disabled, TRUE,
  305.         TAG_END
  306.     );
  307.     SetGadgetAttrs
  308.     (   icon_gadgets[GID_12_BU4], MainWindowPtr, NULL,
  309.         GA_Disabled, FALSE,
  310.         TAG_END
  311.     );
  312.     SetAttrs
  313.     (   Window12Object,
  314.         WA_BusyPointer, TRUE,
  315.         TAG_END
  316.     );
  317.                           
  318.     convert(TRUE);
  319.  
  320.     if (!stop)
  321.     {   SetGadgetAttrs
  322.         (   icon_gadgets[GID_12_ST2], MainWindowPtr, NULL,
  323.             STRINGA_TextVal, "All done.",
  324.             TAG_END
  325.         );
  326.     }
  327.     SetAttrs
  328.     (   Window12Object,
  329.         WA_BusyPointer, FALSE,
  330.         TAG_END
  331.     );
  332.     SetGadgetAttrs
  333.     (   icon_gadgets[GID_12_CH1], MainWindowPtr, NULL,
  334.         GA_Disabled, FALSE,
  335.         TAG_END
  336.     );
  337.     SetGadgetAttrs
  338.     (   icon_gadgets[GID_12_CB1], MainWindowPtr, NULL,
  339.         GA_Disabled, FALSE,
  340.         TAG_END
  341.     );
  342.     SetGadgetAttrs
  343.     (   icon_gadgets[GID_12_CB2], MainWindowPtr, NULL,
  344.         GA_Disabled, FALSE,
  345.         TAG_END
  346.     );
  347.     SetGadgetAttrs
  348.     (   icon_gadgets[GID_12_ST1], MainWindowPtr, NULL,
  349.         GA_Disabled, FALSE,
  350.         TAG_END
  351.     );
  352.     SetGadgetAttrs
  353.     (   icon_gadgets[GID_12_BU1], MainWindowPtr, NULL,
  354.         GA_Disabled, FALSE,
  355.         TAG_END
  356.     );
  357.     SetGadgetAttrs
  358.     (   icon_gadgets[GID_12_BU2], MainWindowPtr, NULL,
  359.         GA_Disabled, FALSE,
  360.         TAG_END
  361.     );
  362.     SetGadgetAttrs
  363.     (   icon_gadgets[GID_12_BU3], MainWindowPtr, NULL,
  364.         GA_Disabled, FALSE,
  365.         TAG_END
  366.     );
  367.     SetGadgetAttrs
  368.     (   icon_gadgets[GID_12_BU4], MainWindowPtr, NULL,
  369.         GA_Disabled, TRUE,
  370.         TAG_END
  371.     );
  372. }
  373.  
  374. AGLOBAL void iconconvert(ABOOL gui)
  375. {   TEXT               saystring[LONGFIELD + 1];
  376.     ULONG              length = strlen(shared.thisfile);
  377.     struct DiskObject* IconPtr;
  378.  
  379.     if (length <= 5) // in case we get passed an empty string
  380.     {   return;
  381.     }
  382.     if (!stricmp(&(shared.thisfile[length - 5]), ".info"))
  383.     {   shared.thisfile[length - 5] = 0;
  384.     }
  385.    
  386.     strcpy(saystring, "Processing ");
  387.     strcat(saystring, shared.thisfile);
  388.     strcat(saystring, ".info...");
  389.     if (gui)
  390.     {   SetGadgetAttrs
  391.         (   icon_gadgets[GID_12_ST2], MainWindowPtr, NULL,
  392.             STRINGA_TextVal, saystring,
  393.             TAG_END
  394.         );
  395.     } else
  396.     {   Printf("%s", saystring);
  397.         Flush(Output());
  398.         saystring[0] = 0;
  399.     }
  400.  
  401.     if (IconPtr = GetIconTags(shared.thisfile, TAG_DONE))
  402.     {   IconPtr->do_Type = (UWORD) icon.type;
  403.         if (PutIconTags(shared.thisfile, IconPtr,
  404.             ICONPUTA_NotifyWorkbench,     TRUE,
  405.             ICONPUTA_DropPlanarIconImage, (BOOL) !icon.planar,
  406.             ICONPUTA_OptimizeImageSpace,  (BOOL) icon.optimize,
  407.             TAG_DONE
  408.         ))
  409.         {   strcat(saystring, "done.");
  410.         } else strcat(saystring, "failed to write!");
  411.     } else strcat(saystring, "failed to read!");
  412.  
  413.     if (gui)
  414.     {   SetGadgetAttrs
  415.         (   icon_gadgets[GID_12_ST2], MainWindowPtr, NULL,
  416.             STRINGA_TextVal, saystring,
  417.             TAG_END
  418.         );
  419.     } else
  420.     {   Printf("%s\n", saystring);
  421.     }
  422.  
  423.     checkabort(gui);
  424. }
  425.  
  426. AGLOBAL void icon_loop(ULONG gid)
  427. {   STRPTR stringptr;
  428.  
  429.     switch (gid)
  430.     {
  431.     case GID_12_CH1:
  432.         if (!(GetAttr
  433.         (   CHOOSER_Selected, icon_gadgets[GID_12_CH1], (ULONG *) &(icon.type)
  434.         )))
  435.         {   rq("Unsupported inquiry!"); // should never happen
  436.         }
  437.         icon.type++;
  438.     break;
  439.     case GID_12_ST1:
  440.         if (!(GetAttr
  441.         (   STRINGA_TextVal, icon_gadgets[GID_12_ST1], (ULONG *) &stringptr
  442.         )))
  443.         {   rq("Unsupported inquiry!"); // should never happen
  444.         }
  445.     break;
  446.     case GID_12_BU1:
  447.         multiasl("#?.info");
  448.         SetGadgetAttrs
  449.         (   icon_gadgets[GID_12_ST1], MainWindowPtr, NULL,
  450.             STRINGA_TextVal,  shared.pathname,
  451.             TAG_END
  452.         );
  453.     break;
  454.     case GID_12_BU2:
  455.         page = 0;
  456.     break;
  457.     case GID_12_BU3:
  458.         icon_do();
  459.     break;
  460.     case GID_12_CB1:
  461.         if (!(GetAttr
  462.         (   GA_Selected, icon_gadgets[GID_12_CB1], (ULONG *) &(icon.optimize)
  463.         )))
  464.         {   rq("Unsupported inquiry!"); // should never happen
  465.         }
  466.     break;
  467.     case GID_12_CB2:
  468.         if (!(GetAttr
  469.         (   GA_Selected, icon_gadgets[GID_12_CB2], (ULONG *) &(icon.planar)
  470.         )))
  471.         {   rq("Unsupported inquiry!"); // should never happen
  472.         }
  473.     break;
  474.     default:
  475.     break;
  476. }   }
  477.  
  478. AGLOBAL ULONG Hook12Func(struct Hook *h, VOID *o, VOID *msg)
  479. {   /* "When the hook is called, the data argument points to the 
  480.     window object and message argument to the IntuiMessage." */
  481.  
  482.     UWORD code, qual;
  483.  
  484.     geta4(); // wait till here before doing anything
  485.  
  486.     code = ((struct IntuiMessage *) msg)->Code;
  487.     qual = ((struct IntuiMessage *) msg)->Qualifier;
  488.  
  489.     switch(code)
  490.     {
  491.     case SCAN_HELP:
  492.         helpabout();
  493.     break;
  494.     case SCAN_ESCAPE:
  495.         if ((qual & IEQUALIFIER_LSHIFT) || (qual & IEQUALIFIER_RSHIFT))
  496.         {   cleanexit(EXIT_SUCCESS);
  497.         } else page = 0;
  498.     break;
  499.     case SCAN_P:
  500.         ActivateLayoutGadget(icon_gadgets[GID_12_LY1], MainWindowPtr, NULL, (Object) icon_gadgets[GID_12_ST1]);
  501.     break;
  502.     default:
  503.     break;
  504.     }
  505.  
  506.     return(1);
  507. }
  508.  
  509. AGLOBAL void icon_die(void)
  510. {   IOBuffer[16] = (UBYTE) icon.type;
  511.     IOBuffer[17] = (UBYTE) icon.optimize;
  512.     IOBuffer[18] = (UBYTE) icon.planar;
  513. }
  514.  
  515. AGLOBAL void icon_config(void)
  516. {   icon.type     = IOBuffer[16];
  517.     icon.optimize = IOBuffer[17];
  518.     icon.planar   = IOBuffer[18];
  519. }
  520.  
  521.